package com.undsf.utility;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Arathi on 2016/10/14.
 */
public class Table2D<T> {
    protected int width;
    protected int height;
    protected T[][] rawdata;

    public Table2D(int width, int height) {
        this.width = width;
        this.height = height;
        rawdata = (T[][])new Object[width][height];
    }

    public void setData(int x, int y, T data) {
        rawdata[x][y] = data;
    }

    public T getData(int x, int y) {
        return rawdata[x][y];
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public List<T> toLinearList() {
        List<T> list = new ArrayList<T>();
        for (int x=0; x<width; x++) {
            for (int y=0; y<height; y++) {
                T data = rawdata[x][y];
                list.add(data);
            }
        }
        return list;
    }
}
